{% extends 'admin/public/base.html' %}

{% block title %}
<title>类别管理--列表</title>
{% endblock %}

{% block con %}            

<div class="row">

    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf">
            <div class="widget-body  widget-body-lg am-fr">
                
                <!-- 内容区域 -->            
                <div class="row-content am-cf">
                    <div class="row">
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                            <div class="widget am-cf">
                                <div class="widget-head am-cf">
                                    <div class="widget-title  am-cf">文章列表</div>
                                </div>
                                <div class="widget-body  am-fr">
                                    <!-- 4颜色标签 -->
                                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                        <div class="am-form-group">
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 搜索条件 -->
                                    <form action="" method="get">
                                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                            <div class="am-form-group tpl-table-list-select">
                                                <select name="types" data-am-selected="{btnSize: 'sm'}">
                                                  
                                                  <option {% if request.GET.types == 'all' %} selected {% endif %} value="all">所有类别</option>                                                  
                                                  <option {% if request.GET.types == 'name' %} selected {% endif %} value="name">分类名</option>
                                                  <option {% if request.GET.types == 'fu_name' %} selected {% endif %} value="fu_name">所属类</option>                                
                                                </select>
                                            </div>
                                        </div>
                                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                              
                                                <input value="{{ request.GET.keywords }}" name="keywords" type="text" class="am-form-field">
                                                <span class="am-input-group-btn">
                                                    <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                                                 </span>
                                            </div>
                                        </div>
                                    </form>

                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                        <thead>
                                            <tr>
                                                <th>ID</th>  
                                                <th>分类名</th>
                                                <th>所属类</th>                                                                      
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>                                
                                            {% for i in info %}
                                            <tr class="gradeX">                                                
                                                <td class='typeid' >{{ i.id }}</td>
                                                <td>
                                                    {% if i.pid != 0 %}
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                                    {% endif %}
                                                    <span class="xxxname">{{ i.name }}</span>                                                    
                                                </td>
                                                <td>
                                                    {% if i.pid != 0 %}
                                                        <span>{{ i.fu_name }}</span>
                                                    {% endif %}
                                                </td>
                                                <td>
                                                    <div class="tpl-table-black-operation">
                                                        <a href="javascript:void(0)" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-trash"></i> 删除
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>           
                                            {% endfor %}                             
                                        </tbody>
                                    </table>



                                    <!-- 右下角分页 -->
                                    <div class="am-u-lg-12 am-cf">
                                        <div class="am-fr">
                                            <ul class="am-pagination tpl-pagination">                                                
                                                <!-- 导入 存放 自定义标签的.py文件 -->
                                                {% load pagetag %}                  
                                                <!-- 调用自定义过滤器                                                      
                                                    功能:1.显示标签
                                                        2.带跳转功能  
                                                    参数: 方法名字
                                                          showpage  

                                                          总页数
                                                          data.paginator.num_pages
                                                          
                                                          当前页数
                                                          request
                                                -->
                                                {% showpage info.paginator.num_pages request %}                                                                                                
                                                                                                                                            
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/javascript" >
    



    // 找到name元素,绑定双击时间
    $('.xxxname').dblclick(function(){
        // 获取当前元素的值,现有的类名
        var yname = $(this).text()
        // 获取当前元素的 id
        var id    = $(this).parents('tr').find('.typeid').text()
        // 创建以input 放置到 当前元素的位置
        var inp = $('<input type="text" value="'+yname+'" style="color:black;">')
        // 把input添加到当前元素的位置
        $(this).html(inp)
        // 双击后将 框框中的内容全内容全部
        inp.select()
        var span = $(this)

        // 给input绑定丧失焦点事件
        inp.blur(function(){
            // 获取当前input中的值
            var newname = $(this).val()
            console.log(newname)
            // 判断当前的name是否修改
            if(yname == newname){
                span.html(yname)
            }else{
                $.get('{% url "myadmin_types_update" %}',{'newname':newname,'id':id},function(){
                    // 成功
                    span.html(newname)
                })               
            }
        })
    });


    //获取删除按钮 绑定单机时间
    $('.tpl-table-black-operation-del').click(function(){
        var id = $(this).parents('tr').find('.typeid').text()
        var d = $(this)
        // 发送ajax请求,传送id
        $.get('{% url "myadmin_type_delete" %}',{'id':id},function(data){
            if(data.error == 0){
                // 删除成功,删除当前元素
                d.parents('tr').remove()
            }
            alert(data.msg)
        },'json')
    })
</script>
{% endblock %}      




